<template>
  <div class="list">
    <van-sticky>
      <div class="top-background">
        <div class="return">
          <img src="../assets/images/Return.png" alt="" @click="getBack" />
        </div>
        <div class="txt">
          排行榜
          <img src="../assets/images/list.png" alt="" />
        </div>
      </div>
    </van-sticky>

    <div class="content">
      <van-sticky :offset-top="150">
        <van-tabs v-model="active" @click="getNavId(active)">
          <van-tab
            :title="item.clusterName"
            v-for="(item, index) in listNavData"
            :key="index"
          >
          </van-tab>
        </van-tabs>
      </van-sticky>

      <div class="menu">
        <div class="menu-box">
          <div class="menu-left">
            <van-sticky :offset-top="194">
              <van-sidebar v-model="activeKey">
                <van-sidebar-item
                  :title="value.moduleName"
                  v-for="(value, i) in listSiderData"
                  :key="i"
                  @click="getSiderId(i)"
                />
                <!-- <van-sidebar-item title="标签名称" />
              <van-sidebar-item title="标签名称" /> -->
              </van-sidebar>
            </van-sticky>
          </div>
          <div class="menu-right">
            <!-- 商品 -->
            <div class="product-box">
              <div class="product-item">
                <!-- <Product :pro="item" /> -->
                <van-card
                  price="2.00"
                  :desc="item.albumInfo.salePoint"
                  :title="item.albumInfo.title"
                  :thumb="imgSrc + item.albumInfo.cover"
                  v-for="(item, index) in cardData"
                  :key="index"
                >
                  <template #footer>
                    <van-button size="mini" round type="danger" class="bottom-button"><van-icon name="plus" color="#fff" />订阅</van-button>
                  </template>
                </van-card>

                <van-empty description="没有内容" />
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "list",

  data() {
    return {
      active: 0,
      listNavData: [],
      activeKey: 1,
      listSiderData: [],
      cardData: [],
      imgSrc: "//imagev2.xmcdn.com/",
      nav: "hotplay",
      sider: "youshengshu",
    };
  },
  created() {
    this.getListNavData();
    this.getNavData();
    this.getCardData(this.nav);
  },
  methods: {
    getBack() {
      this.$router.go(-1);
    },
    getListNavData() {
      this.axios({
        method: "get",

        url: "https://apis.netstart.cn/ximalaya/rank/queryRankClusterDetail",
      })
        .then((val) => {
          this.listNavData = val.data.data;
          // console.log(this.listNavData);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getNavData() {
      this.axios({
        method: "get",

        url: "https://apis.netstart.cn/ximalaya/index/queryIndexTabModule",
      })
        .then((result) => {
          // console.log(result);
          if (result.status === 200) {
            this.listSiderData = result.data.data;
            // console.log(this.listSiderData);
            // console.log(result.data.data.slice(0,-2));
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    getCardData(nav) {
      this.axios({
        method: "get",

        url: "https://apis.netstart.cn/ximalaya/rank/queryRank?",
        params: {
          clusterCode: this.nav,
          categoryCode: this.sider,
        },
      })
        .then((result) => {
          this.cardData = result.data.data.rankModuleInfoList;
          if (this.cardData === "") {
            this.flag = true;
          }
          // console.log(result.data.data.rankModuleInfoList);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getNavId(index) {
      // console.log(index);
      this.nav = this.listNavData[index].clusterCode;
      this.getCardData();
      // console.log(this.nav);
    },
    getSiderId(index) {
      // console.log(this.listSiderData[index].moduleKey);
      this.sider = this.listSiderData[index].moduleKey;
      this.getCardData();
    },
  },
};
</script>

<style lang="less" scoped>
.top-background {
  display: flex;
  top: 0;
  left: 0;
  width: 100%;
  height: 150px;
  background-color: rgb(255, 203, 102);
  .return {
    img {
      width: 20px;
      margin-left: 5px;
      margin-top: 15px;
    }
  }
  .txt {
    font-size: 36px;
    color: #fff;
    margin-top: 10px;
    margin-left: 10px;
    img {
      margin-left: 100px;
      width: 60px;
      margin-top: 20px;
    }
  }
}
.menu-box {
  display: flex;
  height: calc(100% - 50px);
  .menu-left {
    width: 80px;
    height: 100%;
    background-color: #f7f8fa;
    display: flex;
    top: 194px;
    left: 0;
    overflow-y: auto;
    /deep/ .van-sidebar {
      width: 100%;
    }
    /deep/ .van-sidebar-item--select::before {
      width: 2px;
      height: 60%;
      //   background-color: #0C34BA;
    }
  }
  .menu-right {
    width: calc(100% - 90px);
    height: 100%;
    overflow-y: auto;
    padding-left: 10px;
    padding-right: 10px;
    background-color: #fff;
  }
}
.bottom-button{
  background-color: rgb(252,99,16);
}
</style>